package com.qf.spring22022.controller;


import com.baomidou.kaptcha.Kaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/kapchar")
public class KapcharController {
    @Autowired
    Kaptcha kaptcha;

    @GetMapping("/render")
    public void render() {
        kaptcha.render();
    }

    @GetMapping("/valid/{code}")
    public void validDefaultTime(@PathVariable("code") String code) {
        //default timeout 900 seconds
        Boolean flag = kaptcha.validate(code);
        System.out.println(flag);
    }

    @GetMapping("/validTime/{code}")
    public void validCustomTime(@PathVariable("code") String code) {
        boolean flag = kaptcha.validate(code, 20);
        System.out.println(flag);
    }
}
